home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Genie / Projects / V3DDemo / Source / Sources / V3DPanePort.cc < prev   
Encoding:
C/C++ Source or Header  |  2000-06-24  |  3.3 KB  |  214 lines

  1. /*    ==============
  2.  *    V3DPanePort.cc
  3.  *    ==============
  4.  */
  5.  
  6. #include "PedestalDebugging.h"
  7.  
  8. #include <MacWindows.h>
  9.  
  10. #include "V3DPanePort.hh"
  11.  
  12. #include "Ped1AppProcess.hh"
  13. #include "PedApplication.hh"
  14. #include "PedView.hh"
  15.  
  16. #include "C3DObjects.hh"
  17. #include "C3DPort.hh"
  18.  
  19.  
  20. V3DPanePort::V3DPanePort(PedView &inSuperView, C3DModel &inModel)
  21. : PedPane(inSuperView), mPort(NULL)
  22. {
  23.     mPort = new C3DPort(inModel);
  24.     C3DCamera *camera = new C3DCamera;
  25.     camera->viewAngle = 2 / 1.0;
  26.     mPort->SetCamera(camera);
  27. }
  28.  
  29. V3DPanePort::~V3DPanePort()
  30. {
  31. }
  32.  
  33. void
  34. V3DPanePort::Init()
  35. {
  36.     if (!mPort) {
  37.     }
  38. }
  39.  
  40. void
  41. V3DPanePort::Open()
  42. {
  43.     if (!mPort) {
  44.         Init();
  45.     }
  46.     
  47.     PedPane::Open();
  48.     
  49.     //::SetPort(macWindow);
  50. }
  51.  
  52. void
  53. V3DPanePort::Close()
  54. {
  55.     if (mPort) {
  56.         delete mPort;
  57.         mPort = NULL;
  58.     }
  59.     
  60.     PedPane::Close();
  61. }
  62.  
  63. void
  64. V3DPanePort::Activate()
  65. {
  66. }
  67.  
  68. void
  69. V3DPanePort::Deactivate()
  70. {
  71. }
  72.  
  73. void
  74. V3DPanePort::Resize(short inWidth, short inHeight)
  75. {
  76.     PedPane::Resize(inWidth, inHeight);
  77.     
  78.     //if (mSuperView.IsOpen())
  79.     //    ::InvalRect(&mBounds);
  80. }
  81.  
  82. void
  83. V3DPanePort::Draw()
  84. {
  85.     //PedWindow::Draw();
  86.     
  87.     if (!mPort) return;
  88.     
  89.     ::EraseRect(&qd.thePort->portRect);
  90.     
  91.     // Plot the images in screen coordinates
  92.     mPort->GetCameraFrame();
  93.     C3DPoint *pt = mPort->mPoints.FirstDatum();
  94.     while (pt) {
  95.         double x, y, z;
  96.         Point ptMac;
  97.         short width, height;
  98.         
  99.         width = qd.thePort->portRect.right - qd.thePort->portRect.left;
  100.         height = qd.thePort->portRect.bottom - qd.thePort->portRect.top;
  101.         
  102.         x = pt->Cell(0, 0);
  103.         //y = pt->Cell(0, 1);
  104.         z = pt->Cell(0, 2);
  105.         
  106.         // Use height as coefficient
  107.         ptMac.h = height * x + width / 2;
  108.         ptMac.v = height - (height * z + height / 2);
  109.         
  110.         PenSize(2, 2);
  111.         MoveTo(ptMac.h, ptMac.v);
  112.         Line(0, 0);
  113.         
  114.         // We need a list iterator!
  115.         pt = mPort->mPoints.Successor(pt);
  116.     }
  117. }
  118.  
  119. void
  120. V3DPanePort::DispatchNullEvent(EventRecord &inEvent)
  121. {
  122.     ::GlobalToLocal(&inEvent.where);
  123.     if (::PtInRect(inEvent.where, &qd.thePort->portRect)) {
  124.         CursHandle cursCross = ::GetCursor(crossCursor);
  125.         ThrowIfNULL_(cursCross);
  126.         ::SetCursor(*cursCross);
  127.     } else
  128.         ::SetCursor(&qd.arrow);
  129.     if (mPort) {
  130.         //mPort->Animate();
  131.         //mSuperView->Focus();
  132.         //Draw();
  133.     }
  134. }
  135.  
  136. void
  137. V3DPanePort::DispatchClickEvent(EventRecord &inEvent)
  138. {
  139.     if (mPort == NULL)
  140.         return;
  141.     
  142.     //::SetPort(macWindow);
  143.     ::GlobalToLocal(&inEvent.where);
  144.     //::TEClick(inEvent.where, inEvent.modifiers & shiftKey != 0, macTE);
  145. }
  146.  
  147. void
  148. V3DPanePort::DispatchKey(EventRecord &inEvent)
  149. {
  150.     char c = inEvent.message & charCodeMask;
  151.     if (0) {
  152.         short code = (inEvent.message & keyCodeMask) >> 8;
  153.     } else {
  154.         DoKey(c);
  155.     }
  156. }
  157.  
  158. void
  159. V3DPanePort::DoKey(char inChar)
  160. {
  161.     if (mPort) {
  162.         short cmd;
  163.         switch (inChar) {
  164.             case '7':
  165.                 cmd = cmdMoveLeft;
  166.                 break;
  167.             case '9':
  168.                 cmd = cmdMoveRight;
  169.                 break;
  170.             case '4':
  171.                 cmd = cmdYawLeft;
  172.                 break;
  173.             case '6':
  174.                 cmd = cmdYawRight;
  175.                 break;
  176.             case '1':
  177.                 cmd = cmdRollLeft;
  178.                 break;
  179.             case '3':
  180.                 cmd = cmdRollRight;
  181.                 break;
  182.             case '8':
  183.                 cmd = cmdPitchDown;
  184.                 break;
  185.             case '5':
  186.                 cmd = cmdPitchUp;
  187.                 break;
  188.             case '0':
  189.                 cmd = cmdMoveForward;
  190.                 break;
  191.             case '.':
  192.                 cmd = cmdMoveBackward;
  193.                 break;
  194.             case '-':
  195.                 cmd = cmdMoveUp;
  196.                 break;
  197.             case '+':
  198.                 cmd = cmdMoveDown;
  199.                 break;
  200.             case '*':
  201.                 cmd = cmdExpand;
  202.                 break;
  203.             case '/':
  204.                 cmd = cmdContract;
  205.                 break;
  206.             default:
  207.                 break;
  208.         }
  209.         mPort->SendCameraCommand(cmd);
  210.         mSuperView.Focus();
  211.         Draw();
  212.     }
  213. }
  214.